package org.dk.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.dk.mapper.TbUserMapper;
import org.dk.pojo.TbUser;
import org.dk.pojo.TbUserExample;
import org.dk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class UserServiceImpl implements UserService {

    @Autowired
    private TbUserMapper tbUserMapper;
    @Override
    public TbUser selectByName(String username) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(example);
        return tbUsers == null || tbUsers.size() <= 0 ? null : tbUsers.get(0);
    }

    @Override
    public void insertUser(TbUser user) {
        tbUserMapper.insertSelective(user);
    }

    @Override
    public TbUser getPassWord(String email, String phone) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andEmailEqualTo(email);
        criteria.andPhoneEqualTo(phone);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(example);
        return tbUsers == null || tbUsers.size() <=0 ? null : tbUsers.get(0);
    }

    @Override
    public void updateUser(TbUser user) {
        tbUserMapper.updateByPrimaryKeySelective(user);
    }
}
